<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // typeof
        // 需要注意的是，通过typeof所检测值的时候，object、array、null都会返回object
        console.log(typeof 1);
        console.log(typeof NaN);
        console.log(typeof true);
        console.log(typeof '1');
        console.log(typeof null);
        console.log(typeof {});
        console.log(typeof []);
        console.log(typeof function () { });

        console.log('--------------------------------');

        // instanceof(检测某一个实例是否属于这个类)
        // 可以正确判断对象的类型，但是不能正确判断基本数据类型，内部运行机制，判断在它的原型链上能否找到这个类型的原型
        console.log(10 instanceof Number);
        console.log(true instanceof Boolean);
        console.log('10' instanceof String);
        console.log([] instanceof Array);
        console.log(function () { } instanceof Function);
        console.log({} instanceof Object);

        console.log('--------------------------------');

        // constructor(检测实例和类的关系，从而检测出数据类型)，引用原来构造该对象的函数
        console.log((10).constructor === Number);
        console.log((true).constructor === Boolean);
        console.log(('mika').constructor === String);
        console.log(([]).constructor === Array);
        console.log(({}).constructor === Object);
        console.log(function () { }.constructor === Function);

        console.log('--------------------------------');

        // Object.prototype.toString.call()
        let a = Object.prototype.toString;
        console.log(a.call(10));
        console.log(a.call(true));
        console.log(a.call('mika'));
        console.log(a.call({}));
        console.log(a.call([]));
        console.log(a.call(function(){}));
    </script>
</body>

</html>